import React,{Component} from 'react';

class Rate extends Component {
    constructor(props){
        super(props)

    }

    starClick(val,e){
        e.stopPropagation();
        this.props.onChange(val);
    }

    render(){
        let stars=[];
        for (let i=1;i<6;i++)
        {
            if (i<=this.props.value){
                stars.push(<img src="/assets/wechat/star.png" key={Math.random().toString(16).substring(2)}/>);
            }else{
                stars.push(<img src="/assets/wechat/stra.png" key={Math.random().toString(16).substring(2)}/>);
            }
        }

        return (
            <div className="com-ratebox">
                <div className="starbox">
                    {stars} 
                </div>
                <div className="ctrlbox">
                    <span onClick={this.starClick.bind(this,1)}></span>
                    <span onClick={this.starClick.bind(this,2)}></span>
                    <span onClick={this.starClick.bind(this,3)}></span>
                    <span onClick={this.starClick.bind(this,4)}></span>
                    <span onClick={this.starClick.bind(this,5)}></span>
                    <div className="cb"></div>
                </div>
            </div>
        )
    }
}

export default Rate